const mongoose = require("mongoose");
const { type } = require("os");
const Schema = mongoose.Schema;

const userSchema = new Schema(
    {
        id: { // 自动生成编码
            type: String, require: truwe, unique: true
        },
        account: { // 登录账号
            type: String, require: false,
            minlength: ["5", "登录账号不能小于5个字符"],
            maxlength: ["20", "登录账号不能大于20个字符"]
        },
        password: { // 登录账号密码
            type: String, require: false,
            minlength: ["6", "登录账号不能小于6个字符"],
            maxlength: ["50", "登录账号不能大于50个字符"]
        },
        nick_name: { // 昵称
            type: String, require: false, default: ""
        },
        memo: { // 备注
            type: String, required: false, default: ""
        },
        status: { // 数据记录状态（标志位）： 0，删除；1，正常
            type: Number, required: true, default: 1
        },
        create_user: {  // 创建人
            type: String, require: true
        },
        create_time: { // 创建时间
            type: String, require: true
        },
        update_user: { // 更新人
            type: String, require: false, default: ""
        },
        update_time: { // 更新时间
            type: String, required: false, default: ""
        },
        delete_user: { // 删除人
            type: String, required: false, default: ""
        },
        delete_time: { // 删除记录时间
            type: String, required: false, default: ""
        }
    },
    { versionKey: false }
);

userSchema.index({ account: 1 }, { unique: true });
userSchema.index({ status: 1 })
userSchema.plugin(publicId, {
    namespace: "ur",
    prefix: "_",
    fieldName: "id",
    index: true
})

const UserModel = mongoose.model("User", userSchema);

module.exports = UserModel;
